﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IP.Core.IPCommon;
using WebUS;
using WebDS;

public partial class DanhMuc_Danh_sach_nhan_vien : System.Web.UI.Page
{
    #region Members
    US_DM_NHAN_VIEN m_us_dm_nhan_vien = new US_DM_NHAN_VIEN();
    DS_DM_NHAN_VIEN m_ds_dm_nhan_vien = new DS_DM_NHAN_VIEN();
    #endregion

    #region Data Structures
    #endregion

    #region PrivateMethods
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!this.IsPostBack)
            {
                load_data_2_grid();
            }

        }
        catch (Exception v_e)
        {
            this.Response.Write(v_e.ToString());
        }

    }
    private void load_data_2_grid() {
        try
        {
            m_us_dm_nhan_vien.FillDataset(m_ds_dm_nhan_vien);
            m_grv_dm_nhan_vien.DataSource = m_ds_dm_nhan_vien.DM_NHAN_VIEN;
            m_grv_dm_nhan_vien.DataBind();
        }
        catch (Exception v_e)
        {
            throw v_e;
        }
    }

    #endregion

    #region Events
    #endregion
    protected void m_grv_dm_nhan_vien_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        try
        {
            m_grv_dm_nhan_vien.PageIndex = e.NewPageIndex;
            load_data_2_grid();
        }
        catch (Exception v_e)
        {
            CSystemLog_301.ExceptionHandle(this, v_e);
        }
    }

    protected void m_grv_dm_nhan_vien_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        try
        {
            decimal v_dc_id = CIPConvert.ToDecimal(m_grv_dm_nhan_vien.DataKeys[e.RowIndex].Value);
            Response.Redirect("/VanNienSysProject/ChucNang/Quan_ly_profile_ca_nhan.aspx?ID=" + v_dc_id, false);
           
        }
        catch (Exception v_e)
        {
            CSystemLog_301.ExceptionHandle(this, v_e);
        }
        
    }
    private void delete_dm_nhan_vien(int i_int_row_index)
    {
        try
        {
            decimal v_dc_id_dm_tu_dien = CIPConvert.ToDecimal(m_grv_dm_nhan_vien.DataKeys[i_int_row_index].Value);
            m_us_dm_nhan_vien.DeleteByID(v_dc_id_dm_tu_dien);
            load_data_2_grid();
            m_lbl_thong_bao.Text = "Xóa bản ghi thành công.";
        }
        catch (Exception v_e)
        {
            m_lbl_thong_bao.Text = "Lỗi trong quá trình xóa bản ghi.";
            throw v_e;
        }
    }
    protected void m_grv_dm_nhan_vien_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        try
        {
            
            delete_dm_nhan_vien(e.RowIndex);
        }
        catch (Exception v_e)
        {
            // de su dung CsystemLog_301 bat buoc Site phai dat trong thu muc cap 1. Vi du: DanhMuc/Dictionary.aspx
            CSystemLog_301.ExceptionHandle(this, v_e);
        }
    }
}